import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { BomMRoute, BomProcess } from "@/api/backend/index";

export const useBomProcess = defineStore(Names.bomProcess, {
  state: () => {
    return {
      options: {},
    };
  },
  getters: {},
  actions: {
    //上传工艺数据
    getDept() {
      return new Promise((resolve, reject) => {
        _get(BomProcess + "/export", {}, "json", "")
          .then((res) => {
            console.log(res);
            resolve(res);
          })
          .catch((err) => {
            console.log(err);
            reject(err);
          });
      });
    },
    //工序导入excel文件
    importExcel(data: any) {
      return new Promise((resolve, reject) => {
        _post(BomProcess + "/import", data, "formData", "")
          .then((res) => {
            console.log("导入excel文件", res);
            resolve(res as any);
          })
          .catch((err) => {
            console.log(err);
          });
      });
    },
    //获取工序列表
    getRouteList(filter: any) {
      return new Promise((resolve, reject) => {
        _get(BomProcess + "/list", filter, "json", "")
          .then((res) => {
            console.log(res);
            resolve(res);
          })
          .catch((err) => {
            console.log(err);
            reject(err);
          });
      });
    },
  },
});
